#include "widget.h"
#include "ui_widget.h"

#include <QVBoxLayout>
#include <QLabel>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->stackedWidget->setCurrentIndex(this->index);
    QWidget* w = new QWidget;
    QVBoxLayout* v = new QVBoxLayout(w);
    v->addWidget(new QLabel("哈哈哈"));
    v->addWidget(new QLabel("嘿嘿嘿"));

    ui->stackedWidget->addWidget(w);

    connect(ui->prevBtn, &QPushButton::clicked, [this](){
        this->index--;
        if(this->index == -1)
        {
            this->index = ui->stackedWidget->count() - 1;
        }
        ui->stackedWidget->setCurrentIndex(this->index);
    });
    connect(ui->nextBtn, &QPushButton::clicked, [this](){
        this->index++;
        if(this->index == ui->stackedWidget->count())
        {
            this->index = 0;
        }
        ui->stackedWidget->setCurrentIndex(this->index);
    });
}

Widget::~Widget()
{
    delete ui;
}
